/**  
2011 Accenture, IDC    
Author: Bhumika Udani
Date: 17 February 2011
*/

@isTest
private class customSharingTestClass{
private static Map<String, User> users = new Map<String, User>();

private static list<user> createUser(){

profile p = [Select Id from profile q where profile.Name ='SFA OOR Media Consultants'];  
profile s = [Select Id from profile q where profile.Name ='System Administrator'];  

UserRole rNJ = New UserRole();
rNJ.Name='OOR New Jersey (NNJ) MC1 New';
//rNJ.ParentRoleId =admin.Id;
Insert rNJ ; 
UserRole rSLC = New UserRole();
rSLC.Name='OOR Salt Lake City (SLC) MC1 New';
//rSLC.ParentRoleId =admin.Id;
Insert rSLC ;
Set<String> usrNo = new Set<String>{'1','2','3','4'};

List<User> user_insert = new List<User>();

integer noUser;
for(noUser=0;noUser<5;noUser++){
User user = new User();      
user.UserName = 'TestUser@atti-temp.com'+noUser ;    
user.LastName = 'sharing NJ'+noUser;      
user.Email = 'asdfgh@atti.com';      
user.Alias = 'asd'+noUser;      
user.CommunityNickname = 'asdf'+noUser;       
user.TimeZoneSidKey = 'America/Los_Angeles';      
user.LocaleSidKey = 'en_US';      
user.EmailEncodingKey = 'UTF-8';      
user.ProfileId = p.Id;     
user.UserRoleId = rNJ.Id;   
user.LanguageLocaleKey = 'en_US';   
user.Office__c = 'NJ';       
user_insert.add(user);      
//insert user_nj;
}
    insert user_insert;
     
    user_insert[2].UserRoleId=rSLC.Id;
    user_insert[2].Office__c = 'SLC';

    user_insert[3].UserRoleId=rSLC.Id;
    user_insert[3].Office__c = 'SLC';
    
    user_insert[4].profileId=s.Id;
    //user_insert[4].UserRoleId=admin.id;
    update  user_insert[2];
    update  user_insert[3];
    update  user_insert[4];

    return user_insert;
}

static testMethod void leadNotesTest(){
/*
ID localAdvertiserRecordTypeID = RecordTypeHelper.GetRecordTypeID('Lead', 'Local Advertiser');

List <Lead> newLeads = new List<Lead>();
List <Lead> updatedLeads = new List<Lead>();
List <Lead> changedownerLeads = new List<Lead>();

List <Notes__c> newNotesList = new List<Notes__c>(); 
List<User> userInsertList = new List<User>();

QueueSobject OORSaltLakeCityQueue= [Select QueueId from QueueSobject q where sobjecttype ='Lead'  and queue.name = 'Sharkpool - Salt Lake (SLC)'];  
QueueSobject OORNewJerseyQueue= [Select QueueId from QueueSobject q where sobjecttype ='Lead'  and queue.name = 'Sharkpool - New Jersey (NNJ)' ];

        userInsertList = createUser();
 test.starttest();
       
        Lead l1 = new Lead();
        l1.RecordTypeId = localAdvertiserRecordTypeID;
        l1.Company = 'LeadTesting123456';
        l1.FirstName = 'Lisa';
        l1.LastName = 'Mosn';
        l1.phone = '9994610223';
        l1.Disposition__c = 'Called - Unavailable';
        l1.Primary_Owner__C='test';
        l1.Primary_Owner_ATTUID__c='124235';
        l1.User_Office_Code__c='NNJ';
        l1.User_Office_Name__c='New Jersey';
        l1.Primary_Owner_AFrontier_Employee_ID__c='68886'; 

        system.runAs(userInsertList[0]){
        insert l1;
        //        l1.ownerid = userInsertList[0].id;
        }
   test.stoptest();

  test.starttest();
      
        Lead l2 = new Lead();
        l2.RecordTypeId = localAdvertiserRecordTypeID;
        l2.Company = '123Testing456';
        l2.FirstName = 'ABC';
        l2.LastName = 'Test';
        l2.phone = '9994055777';
        l2.Disposition__c = 'Called - Spoke with DM';
        l2.Primary_Owner__C='test123';
        l2.Primary_Owner_ATTUID__c='124235';
        l2.User_Office_Code__c='SLC';
        l2.User_Office_Name__c='Salt Lake City';
        l2.Primary_Owner_AFrontier_Employee_ID__c='68878'; 

        system.runAs(userInsertList[2]){
        insert l2;
        }
        //l2.ownerid = userInsertList[2].id;
        
        newLeads.add(l1);
        newLeads.add(l2);
     test.stoptest();
  
      List<Lead> leadNotes = new List<Lead>();
        
        Notes__c leadNote1 = new Notes__c();
        Notes__c leadNote2 = new Notes__c();
        //Notes__c leadNote4 = new Notes__c();

        leadNote1.Lead__c=l1.Id;
        leadNote1.Disposition__c='Appt - Presentation';
        
        system.runAs(userInsertList[0]){
        insert leadNote1;
         //.ownerid = userInsertList[0].id;
        }        
        leadNote2.Lead__c=l2.Id;
        leadNote2.Disposition__c='Called - Unavailable';
        
        system.runAs(userInsertList[2]){
        insert leadNote2;
        }
        //leadNote2.ownerid =userInsertList[2].id;
    
      newNotesList.add(leadNote1);
        newNotesList.add(leadNote2);
        
        insert newNotesList;        
        //for (Lead ld :newLeads)
            
            system.runAs(userInsertList[4]){
           // lead ld_new = new lead();
            l1.ownerid = OORNewJerseyQueue.queueid;
            l2.ownerid = OORSaltLakeCityQueue.queueid;
            leadNotes.add(l1);
            leadNotes.add(l2);
            update leadNotes;
            }
            
            system.runAs(userInsertList[4]){
            leadNotes[0].ownerid = userInsertList[1].id;
            leadNotes[1].ownerid = userInsertList[3].id;
            leadNotes[0].Secondary_Owner__c = userInsertList[0].id;
            update leadNotes;
           } 
           
           //   update newLeads;*/
            }          
 static testMethod void accountNotesTest(){/*
 
 test.starttest();

   ID localAdvertiserRecordTypeID1 = RecordTypeHelper.GetRecordTypeID('Account', 'Local OOR Customer');
   List<Account> accountList = new List<account>();
   list<user> userInsertList = new list <user>();
   List <Notes__c> newNotesList = new List<Notes__c>();

           userInsertList = createUser();
 
           Account testAcc = new Account();    
           testAcc.Name = 'UAPO test';
           testAcc.Phone = '5674675675'; 
           testAcc.ownerid = userInsertList[0].id;  
           testAcc.recordTypeid = localAdvertiserRecordTypeID1;   
           
           accountList.add(testAcc);                  
           
           system.runAs(userInsertList[4]){
           insert accountList;
           } 
            
           Notes__c accNote1 = new Notes__c();
           accNote1.account__c=testAcc.Id;
           accNote1.Disposition__c='Appt - Presentation';
        
           system.runAs(userInsertList[0]){
           insert accNote1;
           }//newNotesList[0].account__c=testAcc.Id;
           
           //update newNotesList;
           
           system.runAs(userInsertList[4]){
           accountList[0].ownerid = userInsertList[1].id;
           update accountList;
           } 
test.stoptest();
 */         
}
}